package com.um.jdy.app.shop.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.um.jdy.app.shop.entity.dto.AddCommentDTO;
import com.um.jdy.app.shop.entity.vo.OrderCommentItemVO;
import com.um.jdy.app.shop.manager.ShopOrderCommentManager;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.entity.dto.PageQuery;
import com.um.springboot.starter.orm.entity.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author renjunwei
 * @date 2020/9/19 09:37
 */
@RestController
@RequestMapping("/api/v1/order/comment/")
@SaCheckLogin
@Validated
@Api(tags = "商城订单")
public class ShopOrderCommentController {

    @Autowired
    ShopOrderCommentManager shopOrderCommentManager;


    /**
     * 评价商品
     * @param dto
     * @return
     */
    @ApiOperation("评价订单")
    @PostMapping()
    public Response comment(@Valid @RequestBody AddCommentDTO dto){
        shopOrderCommentManager.comment(dto);
        return Response.success();
    }

    /**
     * 分页查询我的评价
     * @param dto
     * @return
     */
    @ApiOperation("分页查询我的评价")
    @GetMapping("page")
    public Response<Page<OrderCommentItemVO>> getMyCommentPage(@Valid @ModelAttribute PageQuery dto){
        return Response.success(shopOrderCommentManager.getMyCommentPage(dto));
    }

}
